<include file="Public:header" />
<script type="text/javascript" src="__PUBLIC__/style/js/TableFreeze.js"></script>
<style>
	table tbody tr{cursor:move;padding:0px;}
	.table thead>tr>th{padding:3px;}
	.table tbody>tr>td{padding:3px;}
</style>
<script>
$(function(){
	var scroll_width = 5;
	$("#table_div").height(window.innerHeight-$("#table_div").offset().top-10);
	$(window).resize(function(){
		$("#table_div").height(window.innerHeight-$("#table_div").offset().top-10);
		$("#oDivL_tab_Test3").height($("#table_div").height()-scroll_width-1).width($("#oTableLH_tab_Test3").width());
		$("#oDivH_tab_Test3").height($("#oTableLH_tab_Test3").height()).width($("#table_div").width()-scroll_width);
	})
	$("#tab_Test3").FrozenTable(1,0,0);
	$("#oDivL_tab_Test3").height($("#table_div").height()-scroll_width).width($("#oTableLH_tab_Test3").width());
	$("#oDivH_tab_Test3").height($("#oTableLH_tab_Test3").height()).width($("#table_div").width()-scroll_width);
})
</script>
<div class="wrapper wrapper-content">
	<include file="Public:alert" />
    <div class="row">
        <div class="col-lg-12">
			<include file="Setting:setting_left" />
			<div class="col-lg-10 ">
				<div class="table-content clearfix ibox-title" id="right_height" style="padding-top:0px">
					<input type="hidden" name="status_id" id="status_id" value="{$status_id}">
					<div class="col-lg-12">
						<div style="padding:18px 0 10px;border-bottom:1px solid #ddd;font-weight:700;">工作日配置<span style="font-weight: normal;">（自定义时间优先级高于工作日）</span></div>
						<div style="padding:10x;margin:15px 20px;">
							<span >工作日</span>&nbsp;
							<div id="status_a" style="margin-top:10px;">
								<form style="border:1px solid #ddd;padding:15px;" id="content_form">
									<div class="pull-left">
										<select name="year" id="year" class="form-control">
											<volist name="year_list" id="vo">
												<option value="{$vo}" <if condition = "$where_year eq $vo">selected</if>>{$vo}年</option>
											</volist>
										</select>
									</div>
									<div class="pull-left" style="margin-left: 20px;margin-top:5px;">
										<volist name="work_config_list" id="vo">
											<span class="pull-left">
												<div class="checkbox checkbox-primary">
													<input name="rule_id[]" class="work_config_list" id="rule_{$key}" type="checkbox" value="{$key}" <if condition = "in_array($key,$work_config_array)">checked</if>/>
													<label for="rule_{$key}">{$vo}&nbsp;&nbsp;</label>
												</div>
											</span>
										</volist>
									</div>
									<div class="pull-right">
										<a class="btn btn-primary" id="add_config">保存</a>
									</div>
									<div style="clear:both;"></div>
								</form>
							</div>
						</div>
						<div style="padding:10x;margin:15px 20px;">
							<span >自定义时间</span>&nbsp;
							<div class="table-content" style="padding-top:10px">
								<div class="ibox-content mar-top" style="padding-top:20px;">
									<div class="bulk-actions align-left">
										<button onclick="del_status(this)" style="background:#fff;border:1px solid #e3e3e3;color:#000;" type="button" class="btn btn-primary" >&nbsp;{:L('DELETE')}</button>
										<div class="pull-right">
											<a class="btn btn-primary" id="add">添加自定义时间</a>
										</div>
									</div>
								</div>
								<form action="" id="form1" method="post">
									<div class="col-sm-12 ibox-content" style="border-top:none;margin-top:0px;padding:0px;">
										<div class="full-height-scroll" id="table_div" style="left:0px;top:0px;">
											<table class="table table-hover table-striped table_thead_fixed" id="tab_Test3" >
												<notempty name="workrule_list">
												<thead>
													<tr class="tabTh">
														<td style="width:50px;text-align:center;">
															<div class="checkbox checkbox-primary">
																<input type="checkbox" class="check_all"/>
																<label for=""></label>
															</div>
														</td>
														<td>日期</td>
														<td>状态</td>
														<td>操作</td>
													</tr>
												</thead>
												<tbody>
													<volist name="workrule_list" id="vo">
														<tr>
															<td style="text-align:center;">
																<div class="checkbox checkbox-primary">
																	<input name="rule_id[]" class="check_list" type="checkbox" value="{$vo.id}"/>
																	<label for=""></label>
																</div>
															</td>
															<td>{$vo['sdate']|date="Y-m-d",###}</td>
															<td><if condition = "$vo['type'] eq 1">休息<else />工作日</if></td>
															<td><a class="edit" href="javascript:void(0)" rel="{$vo.id}">{:L('EDIT')}</a></td>
														</tr> 
													</volist>
												</tbody>
												<else />
													<tr>
														<td><include file="Public:nodata" /></td>
													</tr>
												</notempty>
											</table>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div style="display:none" id="dialog-edit-workrule" title="自定义时间">
	<div class="spiner-example">
		<div class="sk-spinner sk-spinner-three-bounce">
			<div class="sk-bounce1"></div>
			<div class="sk-bounce2"></div>
			<div class="sk-bounce3"></div> 
		</div>
	</div>
</div>
<script type="text/javascript">
	$("#year").change(function(){
		var year = $('#year').val();
		window.location = "{:U('setting/workrule','year=')}"+year;
	});

	$("#dialog-edit-workrule").dialog({
		autoOpen: false,
		modal: true,
		width: 550,
		maxheight: 500,
		resizable: false,
		position:["center",100],
		buttons: {
			"保存": function () {
				$.ajax({
					type: "post",
					async:false,
					url: "{:U('setting/workruleedit')}", 
					data: $("#status_form1").serialize(),
					async: true,
					success : function(result){
						if(result.status == 1){
							swal({
								title: "设置成功！",
								text: "即将刷新页面!",
								type: "success"
							});
							window.location.href="{:U('setting/workrule')}";
							$(this).dialog("close");
						}else{
							swal({
								title: result.info,
								type: "error"
							});
							return false;
						}
					}
				});
			},
			"取消": function () {
				$(this).dialog("close");
			}
		},
		close:function(){
			$(this).html('');
		}
	});	
	$('#add').click(function(){
		$('#dialog-edit-workrule').dialog('open');
		$('#dialog-edit-workrule').load("{:U('setting/workruleedit')}");
	});

	$('.edit').click(function(){
		var rule_id = $(this).attr('rel');
		$('#dialog-edit-workrule').dialog('open');
		$('#dialog-edit-workrule').load("{:U('setting/workruleedit','rule_id=')}"+rule_id);
	});

	$('#add_config').click(function(){
		$.ajax({
			type: "post",
			async:false,
			url: "{:U('setting/workrule')}", 
			data: $("#content_form").serialize(),
			async: true,
			success : function(result){
				if(result.status != 1){
					swal({
						title: "设置失败，请重试！",
						type: "error"
					});
					return false;
				}else{
					swal({
						title: "设置成功！",
						type: "success"
					});
					window.location.href="{:U('setting/workrule')}";
				}
			}
		});
	});

	function del_status(obj){
		var id_array = new Array();
		$("input.check_list:checked").each(function(){  
			id_array.push($(this).val());
		});
		if(id_array.length == 0){
			swal({
				title: "温馨提示",
				text: "请先选择要删除的日期!",
				type: "warning"
			})
			return false;
		}else{
			swal({
				title: "您确定要删除该日期吗？",
	   			text: "删除后将无法恢复，请谨慎操作！",
				type: "warning",   
				showCancelButton: true,   
				confirmButtonColor: "#DD6B55",   
				confirmButtonText: "是的，我要删除！",
		        cancelButtonText:'让我再考虑一下…',
		        closeOnConfirm:false,
		        closeOnCancel:false
			},
			function(isConfirm){
		        if (isConfirm) {
					$.ajax({
						type: "POST",
						url: "{:U('setting/workruledel')}",
						data: $("#form1").serialize(),
						async: true,
						success: function(data) {
							if(data.status == 1){
								swal({
									title: "删除成功！",
									text: "即将刷新页面!",
									type: "success"
								});
								window.location.href="{:U('setting/workrule')}";
							}else{
								 swal({
									title: "操作失败!",
									text: data.info,
									type: "error"
								});
							}
						}
					});
				} else {
		            swal("已取消","您取消了删除操作！","error");
		        }
		    });
		}
	}
</script>
<include file="Public:footer" />